#coding=utf-8
'''
Created on 2017-04-20

@author: sandy
'''


from pycommon import Pack as packet
from pycommon import Const
from pycommon import RemoteManager
import ServerConfig
from pycommon import Utils
import logging

def loginCenter(count):
    return packet.pack("HHsH",Const.CMD_GATE2CT_LOGIN,RemoteManager.instance.sid,Utils.u2pstr(ServerConfig.instance.public_ip),ServerConfig.instance.public_port)


def transPackToCenter(uid,pid,cmd,pkt):
    return packet.pack("HIHHs",Const.CMD_GATE2CT_TRANS_PKT,uid,pid,cmd,pkt)


def reportCounter(countermap):
    count = len(countermap)
    ret = packet.pack("HH",Const.CMD_GATE2CT_REPORT_COUNTER,count)
    for k,v in countermap.iteritems():
        ret += packet.pack("Hi", k, v)
    return ret

def reportOnlineCounter(count):
    return packet.pack("HHH",Const.CMD_GATE2CT_REPORT_ONLINE,RemoteManager.instance.sid,count)